/*************************************************
 * 预估成本核算单
 ************************************************/
//重写双击事件 
function cbhsDoubClick(prefix,dsId,rowData,winitFunc,wainitFunc,keyVaules){
	var keyVaules="CBHS_ID-"+rowData.CBHS_ID;
	var staticWebUrl = "";
	var initFunc = '';
	var ainitFunc='_all_cbhiddenM';
	var butn_id ='ds_yz_cbhs_yg';
	 _c_aws('bas',"ds_yz_cbhs_yg;ds_yz_cbhs_item1",butn_id,'5;77',staticWebUrl,initFunc,ainitFunc,keyVaules,'2')
}


 
 //成本核算单双击调用的方法
function _c_aws(prefix,dsId,butnId,type,staticWebUrl,initFunc,ainitFunc,keyValues,flag){
	$('#'+prefix+'_totalItem').html('');  // 双击或添加时清空明细界面的合计的div
	// flag 1.添加 2.修改详情 3.复制
	var flagTo =0;
	var dsIds = dsId.split(";");
	var verify="";
	var obj = strToObj(keyValues);// 把keyValue放入其中，将其变为一个obj
	var data = {};
	var gridName="oneChengBen;twoChengBen;threeChengBen;fourChengBen;fiveChengBen;sixChengBen";
	var pdivName =prefix+'_addWinTable';
	var funcId=$(window.parent.document.getElementById(prefix+'_iframe')).attr("funcid");
	if(funcId==null||funcId==undefined||funcId==""){
		console.log("#model.js 中的funcId获取有误，可能导致权限出问题，请及时修改");
	}
	if($('#'+prefix+'_C_save').length>0){
		$("#"+prefix+"_addWinForm").attr("flag",flag);
		$("#"+prefix+"_addWinForm").attr("sflag","m");
		$("#"+prefix+"_addWinForm").attr("pre",prefix);
		if(flag=='2'){  // 详情 /修改
			// 处理界面保存按钮
			$("#"+prefix+"_M_UBUTN a[code="+prefix+"_SAVE_BUT]").attr('sou','2');
			
			$('#'+prefix+'_m_parentPanel').window('open');
			$('#'+prefix+'_totalNum').show();
			$('#'+prefix+'_imageShow').show();
			//清空datagrid中的数据
			$('#oneChengBen').datagrid('loadData', { total: 0, rows: [] }); 
			$('#twoChengBen').datagrid('loadData', { total: 0, rows: [] }); 
			$('#threeChengBen').datagrid('loadData', { total: 0, rows: [] }); 
			$('#fourChengBen').datagrid('loadData', { total: 0, rows: [] }); 	
			$('#fiveChengBen').datagrid('loadData', { total: 0, rows: [] }); 	
			$('#sixChengBen').datagrid('loadData', { total: 0, rows: [] }); 	
			if(ainitFunc != ""){
				eval(ainitFunc).call(this,data,dsId,prefix);
			}
			cbhsAppLoadDataM(dsId,prefix,keyValues);
		}
		//详情界面的权限
		var isRColn=initAinfoPageRight(funcId,keyValues,dsId,prefix,flag,"m");
		analyColnDataRight(dsId,isRColn,{},"m",pdivName,gridName,{});
		
		if(initFunc != ""){
			eval(initFunc).call(this,data,dsId,prefix,keyValues);
		}
		return;
	}
	var div_box = document.createElement("DIV");
	div_box.id = prefix+'_C_save';
	document.body.appendChild(div_box);
	$('#'+prefix+'_C_save').load(_m_url+'singlePages/mqueryFun',// singlePages/sinfoFun'
			{'dsId':dsId,'butnId':butnId,'type':type,'staticWebUrl':staticWebUrl,'initFunc':initFunc,'jspWebUrl':'/model/cbhs/ygcbhs','flag':'2','keyValues':keyValues},
			function(){
				$("#"+prefix+"_addWinForm").attr("flag",flag);
				$("#"+prefix+"_addWinForm").attr("sflag","m");
				$("#"+prefix+"_addWinForm").attr("pre",prefix);
				
				$.parser.parse('#'+prefix+'_m_maddDiv');
				$('#'+prefix+'_m_parentPanel').window({  
					width:document.documentElement.clientWidth+10,  
					height:document.documentElement.clientHeight,  
					top:'0',
					left:'0',
					draggable:false,
					modal:true,
					resizable:false,
					closable:false,
					collapsible:false,
					maximizable:false,
					minimizable:false
				});  
				$('#'+prefix+'_m_parentPanel').window('open');
				resizeGrid();
				var divName = 'bas_addWinTable;oneChengBen;twoChengBen;threeChengBen;fourChengBen;fiveChengBen;sixChengBen';
				var itemDsId = 'ds_yz_cbhs_yg;ds_yz_cbhs_item1;ds_yz_cbhs_item2;ds_yz_cbhs_item3;ds_yz_cbhs_item4;ds_yz_cbhs_item5;ds_yz_cbhs_item6';
				var itemType = '5;77;77;77;77;77;77';
				$.ajax({
					type:'post',
					url:_m_url+'framework/loadMColumnsU',
					data:{'colId':itemDsId,'type':itemType},
					async:false,
					success:function(data){
						if(data ==""){
							alert("您长时间未操作，系统已经自动退出!，请重新登陆");
						}else{
							var typeT = new Array();
							typeT = itemType.split(";");
							divNameT = divName.split(";");
							var dsIds = dsId.split(';');
							$("#" + prefix + "_MXInput input").removeAttr("disabled");
							//给主表和第一个第二个标签写入列
							for(var i = 0; i < typeT.length; i++){
								producePage(data[i],divNameT[i],typeT[i],'');
							}
							 var lastIndex;
							 if(flag =='2'){
								// 处理界面保存按钮
								$("#"+prefix+"_M_UBUTN a[code="+prefix+"_SAVE_BUT]").attr('sou','2');
								$('#'+prefix+'_totalNum').show();
								$('#'+prefix+'_imageShow').show();
								if(ainitFunc != ""){
									eval(ainitFunc).call(this,data,dsId,prefix);
								}
								cbhsAppLoadDataM(dsId,prefix,keyValues);
							 }
						}
					}
				});
				//详情界面的权限
				var isRColn=initAinfoPageRight(funcId,keyValues,dsId,prefix,flag,"m");
				analyColnDataRight(dsId,isRColn,{},"m",pdivName,gridName,{});
				if(initFunc != ""){
					eval(initFunc).call(this,data,dsId,prefix,keyValues);
				}
			});
}

/*************************************************************暂时不使用*******************************************/
//1.添加明细的方法
function _yzfy_addItem(obj,flag){
	var butn_id ='';
	//获取选题Id
	var xtId = $('#bas_addWinTable input[qucln=XT_ID]').val();
	if(xtId == '' || xtId == null){
		$.messager.alert('温馨提示','亲，请先选择选题！');
		return;
	}else{
		if(flag == 1){
			butn_id = 'one_sure1';
		}else if(flag == 2){
			butn_id = 'two_sure1';
		}else if(flag == 3){
			butn_id = 'three_sure1';
		}else if(flag == 4){
			butn_id = 'four_sure1';
		}
		//倒数第二个参数为回调函数yzc_sure1
		_data_qw('yzc','ds_yz_ysfy_cost1',butn_id,'44','yzfyFunc','');
	}
}
//2.添加明细回调的函数（重写查询方法）
function yzfyFunc(prefix){
	_zae_t_dg(prefix);
	//重写查询按钮的方法
	$('#'+prefix+'_commDataLeftD a[id='+prefix+'_dataQuery]').attr('onclick','yzfyItemQuery(this)');
}


//3.查询按钮调用的方法
function yzfyItemQuery(obj){
	var prefix=$(obj).attr('pre');
	var dsId=$(obj).attr('dsid');
	var resultDG = 'DATA_DATALIST';
	var comUseConf='commUseD';
	var otherConfig = "";
	//获取印刷复印单的主键列
	var peId = $('#bas_addWinTable input[qucln=PE_ID]').val();
	if(peId == '' || peId == null){
		peId = 'null';
	}
	otherConfig = "1-PE_ID-"+peId+"-inc|+"; 
	var comUse = parseConfig(prefix+"_"+comUseConf);
	var useConf = otherConfig+comUse;
	$('#'+prefix+"_"+resultDG).datagrid({
		url:_m_url+'framework/loadDataQ',
		queryParams:{'dsId':dsId,'config':useConf},
		onLoadSuccess:function(){
			
		}
	});
}
//4.弹窗的确定按钮 
function _yzc_sure1(flag){
	$('#yzc_DATA_PARENT_PANEL').window('close');
	var selRows = $('#yzc_DATA_DATALIST').datagrid('getSelections');

	var divName = '';
	var tabType = '';
	if(flag == 1){
		divName= 'oneChengBen';
		tabType = 'cbhsTab.001';
	}else if(flag == 2){
		divName= 'twoChengBen';
		tabType = 'cbhsTab.002';
	}else if(flag == 3){
		divName= 'threeChengBen';
		tabType = 'cbhsTab.003';
	}else if(flag == 4){
		divName= 'fourChengBen';
		tabType = 'cbhsTab.004';
	}
	if(flag == 1){
		for ( var i = 0; i < selRows.length; i++) {
	//		var guige = window.parent.dz_clguigefmat(selRows[i].CL_PICI_GUIGE);  //转译过的规格
			var kezhong = window.parent.dz_clkzfmat(selRows[i].CL_PICI_WEIGHT);   //转译过的克重
			$('#'+divName).datagrid('appendRow', {
				GONGYI_PROJECT:selRows[i].GONGYI_PROJECT,
				CL_ID:selRows[i].CL_ID,
				CL_WEIGHT:kezhong,//kezhong+"克"+guige
				OBJ_AMOUNT:selRows[i].CL_AMOUNT,
				OBJ_UNIT:selRows[i].CL_UNIT,
				MAN_BUSINESS:selRows[i].MAN_BUSINESS,
				PE_ITEM_ID:selRows[i].PE_ITEM_ID,
				TAB_TYPE:tabType
			})
		}
	}else{
		for ( var i = 0; i < selRows.length; i++) {
	//		var guige = window.parent.dz_clguigefmat(selRows[i].CL_PICI_GUIGE);  //转译过的规格
			var kezhong = window.parent.dz_clkzfmat(selRows[i].CL_PICI_WEIGHT);   //转译过的克重
			$('#'+divName).datagrid('appendRow', {
				GONGYI_PROJECT:selRows[i].GONGYI_PROJECT,
				CL_ID:selRows[i].CL_ID,
				CL_WEIGHT:kezhong,//kezhong+"克"+guige
				OBJ_AMOUNT:selRows[i].CL_AMOUNT,
				OBJ_UNIT:selRows[i].CL_UNIT,
				MAN_BUSINESS:selRows[i].MAN_BUSINESS,
				PE_ITEM_ID:selRows[i].PE_ITEM_ID,
				GONGYI_AMOUNT:selRows[i].GONGYI_AMOUNT,
				GONGYI_UNIT:selRows[i].GONGYI_UNIT,
				GONGYI_YSMEMO:selRows[i].GONGYI_YSMEMO,
				GONGYI_EXPLAIN:selRows[i].GONGYI_EXPLAIN,
				GONGYI_YSSS:selRows[i].GONGYI_YSSS,
				TAB_TYPE:tabType
			})
		}
	}
}

//返回
function cbhsRowBak(obj){
	var closeFlag=true;   // 返回false就取消关闭
	var prefix=$(obj).attr("pre");
	var sflag=$(obj).attr("sflag");
	var keyVaules_m = parsePKStr(prefix+"_addWinForm");
	if(sflag=='m'){    // 主明细
		var m_key=keyVaules_m.split("-")[0];
		var m_val=keyVaules_m.split("-")[1];
		if(typeof(m_val)=='undefined'||m_val==""||m_val==undefined||m_val=='undefined'){   // 添加页面
			
		}else {
	        // 详情页面
			// 遍历页面所有元素判断是否有元素发生改变
			var values=getFormJsons(prefix+"_addWinForm");    // 得到主表的数据
			var changes = new Array();
			var divNames = "oneChengBen;twoChengBen;threeChengBen;fourChengBen";
			var oneName = divNames.split(";");
			for(var u=0;u<oneName.length;u++){
				var chanRows = $('#'+oneName[u]).datagrid('getChanges'); 
				for(var i =0;i<chanRows.length;i++){
					changes.push(chanRows[i]);
				}
			}
			if(values==0&&changes==0){
				$('#'+prefix+'_m_parentPanel').window('close');  // 没有修改表单任何元素的时候直接关闭
			}else{   // 有修改元素的时候
				$.messager.confirm("操作提示", "数据已经改变，您确认保存吗？", function (data) {
					if (data){
						$(obj).attr("flag","1");
						$(obj).attr("oflag","1");
						$(obj).attr("sou","2");
						$(obj).attr("isBack","true")
						cbhsSave(obj);  // 确认按钮调用保存事件
						closeFlag=false;
					}else{
						$('#'+prefix+'_m_parentPanel').window('close');  // 取消直接关闭
					}
				});
			}
		}
	}
}
/*******************************************************************************************/
//删除
function cbhsitemRowDel(divName){
	var row = $('#'+divName).datagrid('getSelections');
	if(row.length == 0){
		$.messager.alert("操作提示","请选择一条记录,再进行删除！","info");
		return;
	}else{
		for(var i =0;i<row.length;i++){
			var rowIndex= $('#'+divName).datagrid('getRowIndex',row[i]);
			$('#'+divName).datagrid('deleteRow',rowIndex);
		}
	}
}
//陈本核算单个性化保存
function cbhsSave(obj){
	var sflag = $(obj).attr('sflag');
	var dsId = $(obj).attr('dsId');
	var prefix = $(obj).attr('pre');
	var sou =  $(obj).attr('sou');  
	var mapRecords=new Array();
	var oflag=$(obj).attr("oflag");   // 是否是特殊的保存
	var isCopy=$(obj).attr("isCopy");
	var isBack=$(obj).attr("isBack");    // 标志是不是保存返回按钮的保存 是的时候panle关闭
	if(sflag =='m' ){
		// 主明细表保存
		var zhuPk;   // 保存主表的主键名
		var zhuPkval; // 保存主表的主键值
		var maps=new Array();
		var index=0;
		var formid = prefix+"_addWinForm";
		var mapRecords = new Array();
		var mapRecord;
		if(checkRequire(formid) != "Success")return;
		var values=getFormJsons(formid);// 将form中的值转换为键值对
		var zdsId=dsId.split(";")[0];
		var mdsId=dsId.split(";")[1];
		var mapRecord;
		if(sou==2){
			// 修改
			mapRecord={"diu":"1","dsid":zdsId,'mapRecord':values};
		} 
		// 保存后保存主键和主键的值
		$("#"+formid+" input").each(function(){
			if(typeof($(this).attr('vpk')) != 'undefined' && $(this).attr('vpk') == 'T'){
				zhuPk=$(this).attr('qucln');
				zhuPkval=$(this).val();
			}
		});
		var row ={};
		var deleteRows = new Array();
		var updateRows = new Array();
		var inserteRows =  new Array();
		//循环关闭每个标签中的datagrid的editor
		var divNames = "oneChengBen;twoChengBen;threeChengBen;fourChengBen;fiveChengBen;sixChengBen";
		var oneName = divNames.split(";");
		for(var u=0;u<oneName.length;u++){
			var allRows =$('#'+oneName[u]).datagrid('getRows');
			for(var i=0;i<allRows.length;i++){
				$('#'+oneName[u]).datagrid('endEdit',i);
			}
			var delR = $('#'+oneName[u]).datagrid('getChanges','deleted');
			for(var k=0;k<delR.length;k++){
				deleteRows.push(delR[k]);
			}
			var updR = $('#'+oneName[u]).datagrid('getChanges','updated'); 
			for(var l=0;l<updR.length;l++){
				updateRows.push(updR[l]);
			}
			var insR = $('#'+oneName[u]).datagrid('getChanges','inserted');
			for(var s=0;s<insR.length;s++){
				inserteRows.push(insR[s]);
			}
		}
		var itemPk= eval("window.parent."+mdsId+"_pk");  // 获得明细表的主键
		// 得到明细表中删除的数据
		if(deleteRows.length>0){
			for(var i = 0; i <deleteRows.length ; i++){
				var row= {"diu":"2","dsid":mdsId,'mapRecord':deleteRows[i]};   // 删除时diu明细的标志位2
				mapRecords[index] = row;
				index++;
			}
		}
		// 得到明细表中跟新的数据
		if(updateRows.length>0){
			for(var i = 0; i <updateRows.length ; i++){
				console.log(updateRows[i]);
				var row={"diu":"1","dsid":mdsId,'mapRecord':updateRows[i]};
				mapRecords[index] = row;
				index++;
			}
		}
		
		// 得到明细表中添加的数据
		if(inserteRows.length>0){
			for(var i = 0; i<inserteRows.length ; i++){
				console.log(inserteRows[i]);
				var tmp = {};
				for(p in inserteRows[i]){
					console.log(p+"---"+inserteRows[i][p]);
					tmp[p]=inserteRows[i][p];
				}
				tmp[itemPk]="";   // 明细的主键
				tmp[zhuPk]="";    // 明细的外键
				console.log("明细主键-----"+itemPk);
				var row= {"diu":"0","dsid":mdsId,'mapRecord':tmp};
				mapRecords[index] = row;
				index++;
			}
		}
		
		// 判断有没有对表单和datagrid中的数据进行修改
		if(values==0&&deleteRows.length<=0&&updateRows.length<=0&&inserteRows.length<=0){
			$.messager.show({title:"保存提示",msg:"亲，你没有对数据进行修改，无需保存!",showType:'slide',timeout: 1000,showSpeed:400});
			return;
		}
		if(sou==2){
			// 修改
			if(values==0){
				var o = {};
				o[zhuPk] = zhuPkval;
				mapRecord = {"diu":"1","dsid":zdsId,'mapRecord':o};
				receiveZMobj={"zmReceiveObj":mapRecord,"receiveObjs":mapRecords};// 修改的时候主表的主键一定要传过来
			}else{
				receiveZMobj={"zmReceiveObj":mapRecord,"receiveObjs":mapRecords};// 修改的时候主表的主键一定要传过来
			}
			console.log('---------else-------------');
			console.log(mapRecords);
			console.log('----------------------');
			console.log(receiveZMobj);
			$.ajax({
				url:_m_url+'commsave/commU',
				type:'post',
				contentType: "application/json;charset=utf-8",
				dataType: "json",
				async:false,
				data:JSON.stringify(receiveZMobj),
				success:function(data){
					if(data.msg=='success'){
						for(var u=0;u<oneName.length;u++){
							$('#'+oneName[u]).datagrid('acceptChanges');  // 提交自从被加载以来或最后一次调用acceptChanges以来所有更改的数据，防止重复提交数据
						}
						$("#"+formid+" input").each(function(){
							$(this).removeAttr("chan");
					    });		
						if(isBack=="true"){ 
							$('#'+prefix+'_m_parentPanel').window('close');
						}else{
							if(data.info!=null){
								$.messager.show({title:"保存提示",msg:"o(≧v≦)o~~【亲,修改数据成功】"+(data.info==null?"":data.info),showType:'slide',timeout: 1000,showSpeed:400});
							}else{
								$.messager.show({title:"保存提示",msg:"o(≧v≦)o~~【亲,修改数据成功】"+(data.info==null?"":data.info),showType:'slide',timeout: 1000,showSpeed:400});
							}
						}
						$(obj).removeAttr("isBack");
					}else if(data.msg=='fail'){
						$.messager.show({title:"保存提示",msg:"o(︶︿︶)o【修改数据失败】"+(data.info==null?"":data.info),showType:'slide',timeout: 4000,showSpeed:400});
					}else if(data.msg=="error"){
						$.messager.show({title:"保存提示",msg:"o(︶︿︶)o【修改数据失败】"+(data.info==null?"":data.info),showType:'slide',timeout: 4000,showSpeed:400});
					}
					pkStr = parsePKStr(prefix+"_addWinForm");
					endAppLoadDataM(dsId,prefix,pkStr);
				}
			});
		}
	}
}
/**
 * 保存/修改/审核/审批完成之后刷新数据
 * 
 * @param dsId
 * @param prefix
 * @param keyValues
 * @return
 */
function cbhsAppLoadDataM(dsId,prefix,keyValues){
	var dsIds = dsId.split(";");
	var pdivName =prefix+'_addWinTable';
	$.ajax({
		type:'post',
		url:_m_url+'singlePages/mDataMaD',
		data:{'dsId':dsId,'keyValues':keyValues},
		async:false,
		success:function(dateRow){
			clearFormVal(pdivName);
			loadDzData(pdivName);// 加载下拉框并填充数据
			fillInfo(pdivName,dateRow.queryRow[0][0]);
			cEfect(pdivName,2);
		 
			var oneRows = new Array();
			var oneIndex=0;
			var twoRows = new Array();
			var twoIndex=0;
			var threeRows = new Array();
			var threeIndex=0;
			var fourRows = new Array();
			var fourIndex=0;
			var fiveRows = new Array();
			var fiveIndex=0;
			var sixRows = new Array();
			var sixIndex=0;
			var allRows = dateRow.queryRow[1];
			
//					cbhsTab.001	材料费
//					cbhsTab.002	印刷费
//					cbhsTab.003	装订费
//					cbhsTab.004	工艺费
//					cbhsTab.005   其他费用
//					cbhsTab.006   增加项
			for(var i = 0;i<allRows.length;i++){
				if(allRows[i].TAB_TYPE == 'cbhsTab.001'){
					var tmp = {};
					for( p in allRows[i]){
						tmp[p] = allRows[i][p];
					}
					oneRows[oneIndex]=tmp;
					oneIndex++;
				}else if(allRows[i].TAB_TYPE == 'cbhsTab.002'){
					var tmp = {};
					for( p in allRows[i]){
						tmp[p] = allRows[i][p];
					}
					twoRows[twoIndex]=tmp;
					twoIndex++;
				}else if(allRows[i].TAB_TYPE == 'cbhsTab.003'){
					var tmp = {};
					for( p in allRows[i]){
						tmp[p] = allRows[i][p];
					}
					threeRows[threeIndex]=tmp;
					threeIndex++;
				}else if(allRows[i].TAB_TYPE == 'cbhsTab.004'){
					var tmp = {};
					for( p in allRows[i]){
						tmp[p] = allRows[i][p];
					}
					fourRows[fourIndex]=tmp;
					fourIndex++;
				}else if(allRows[i].TAB_TYPE == 'cbhsTab.005'){
					var tmp = {};
					for( p in allRows[i]){
						tmp[p] = allRows[i][p];
					}
					fiveRows[fiveIndex]=tmp;
					fiveIndex++;
				}else if(allRows[i].TAB_TYPE == 'cbhsTab.006'){
					var tmp = {};
					for( p in allRows[i]){
						tmp[p] = allRows[i][p];
					}
					sixRows[sixIndex]=tmp;
					sixIndex++;
				}
			}
			var o = {rows:oneRows};
			$('#oneChengBen').datagrid("loadData", o);
			var t = {rows:twoRows};
			$('#twoChengBen').datagrid("loadData", t);
			var h = {rows:threeRows};
			$('#threeChengBen').datagrid("loadData", h);
			var f = {rows:fourRows};
			$('#fourChengBen').datagrid("loadData", f);
			var i = {rows:fiveRows};
			$('#fiveChengBen').datagrid("loadData", i);
			var s = {rows:sixRows};
			$('#sixChengBen').datagrid("loadData", s);
			var verify=dateRow.queryRow[0][0].IS_VERIFY;
			var destroy=dateRow.queryRow[0][0].IS_DESTROY;  // 作废 目前没判断
			var divNames = "oneChengBen;twoChengBen;threeChengBen;fourChengBen;fiveChengBen;sixChengBen";
			var oneName = divNames.split(";");
			if((verify!=null&&verify!=0&&verify!=""&&verify!='execState.014'&&verify!='execState.012')||destroy =='1'){
				readOnlyForm(prefix+"_addWinForm");
				for(var u=0;u<oneName.lenght;u++){
					$("#" +oneName[i]).datagrid({
						onClickRow:function(rowIndex,rowData){
							$('#'+oneName[i]).datagrid("cancelEdit",rowIndex);
							$('#'+oneName[i]).attr("currentIndex",rowIndex);
						},onSelect:function(rowIndex,rowData){
							$('#'+oneName[i]).datagrid("cancelEdit",rowIndex);
						},
						onDblClickCell:function(rowIndex,rowData){
							$('#'+oneName[i]).datagrid("cancelEdit",rowIndex);
						}
					});
				}
			}else{
				var lastIndex;
				for(var u=0;u<oneName.lenght;u++){
					$("#" +oneName[i]).datagrid({
						onClickRow:function(rowIndex,rowData){
							$('#'+oneName[i]).attr("currentIndex",rowIndex);
							$('#'+oneName[i]).datagrid('endEdit', lastIndex);
							$('#'+oneName[i]).datagrid('beginEdit', rowIndex);
							lastIndex = rowIndex;
						}
					})
				}
			}
			// 加载状态图片的（审核，审批，作废、、、）
			showDjImgMO(dateRow,prefix);
			// 判断公用的按钮的显示与隐藏
			comButn(dsId,dateRow,prefix,'2',keyValues); 
			//清除缓存，重新根据dsid加载部分对照信息
			window.parent.lzByDsId(dsId);
			//添加和详情页面的回调函数
			var initFunc=$("#"+prefix+"_addWinTable").attr("initfunc");
			if(initFunc!=null&&initFunc!=undefined&&initFunc!=""){
				eval(initFunc).call(this,data,dsId,prefix,keyValues);
			}
			$("#currentPage").html(parseInt(currentRowNo));
			$("#lastPage").html(parseInt(totalCount));
			 if($("div[isMulTabs=true]").length==1){
				 var selectTab=$("div[isMulTabs=true]").tabs('getSelected');
				 curDiv=$(selectTab).find($("div[realdsid][prefix][dsid]"));  // 获取datagrid的div
			 }else if($("div[isMulTabs=true]").length==0){
				 curDiv=$("div[realdsid][prefix][dsid]");  // 获取datagrid的div
			 }
		}
	});
}
//审核作废的方法
function cbhs_desOrApply(obj,aord){  
	if(aord == '0'){    // 作废
		$.messager.confirm("提示","作废后无法还原，确定要作废吗？",function(r){
			if(!r){
				return;
			}else{
				cbhsDesApplyFunc(obj,aord);
			}
		});
	}else if(aord == '1'){   // 审核、审批
		cbhsDesApplyFunc(obj,aord);
	}
}
 //审核和作废
function cbhsDesApplyFunc(obj,aord){
	// 获得页面的前缀
	var prefix = $(obj).attr('pre');
	// 得到审批的表对应的单据dsId
	var dsId=$(obj).attr('dsid');
	var butnCode = $(obj).attr('code');
	var dsIds= dsId.split(';');
	var flag=$(obj).attr('flag');
	var pkStr ="";
	var items='';
	var formId ="";  // 按钮的formId
	var pkVal=""; // 主键值
	var pfks = eval("window.parent."+dsIds[0]+"_pk"); // 主键
	pkStr = parsePKStr(prefix+"_addWinForm");
	pkVal = $('#'+prefix+"_addWinForm input[qucln = "+pfks+"]").val();
	formId = prefix+"_M_UBUTN";
	m_values=getFormJsons(prefix+"_addWinForm");
	var m_changes = new Array();					//获取明细改变的数据
	var divNames = "oneChengBen;twoChengBen;threeChengBen;fourChengBen;fiveChengBen;sixChengBen";
	var oneName = divNames.split(";");
	for(var u=0;u<oneName.length;u++){
		var chanRows = $('#'+oneName[u]).datagrid('getChanges'); 
		for(var i =0;i<chanRows.length;i++){
			m_changes.push(chanRows[i]);
		}
	}
	if(pkVal == null || pkVal==""){     // 添加页面没有保存单据的时候不能审核
		$.messager.alert("提示","单据尚未保存，不能进行其他操作！");
		return;
	}else if(pkVal!=null&&pkVal!=""&&pkVal!='undefined'){   // 修改页面如果数据发上改变那么提示用户是否保存
		 if(flag==2){
			if(m_values==0&&m_changes==0){   // 数据没有发生改变的时候直接审核不需要提示
			}else{   // 有修改元素的时候
				$.messager.alert('操作提示',"数据已经改变,请先进行保存");
				return;
			}
		}
	}
	$.ajax({
		url:_m_url+'store/commDesOrApply',                      
		type :"post",                         
		data :{'dsId':dsId,'pkStr':pkStr,'butnCode':butnCode,'aord':aord},
		dataType:"json",
		success : function(data) {
			// 请求成功后要执行的代码
			if(data.info == "0"){  // 作废
				if(data.msg=="success"){
					if(flag == '2'){
						cbhsAppLoadDataM(dsId,prefix,pkStr);
					}
				}else if(data.msg=='error'){
					if(data.info !=null && data.info !=""){
						$.messager.alert('错误提示',data.msgInfo,"info");
					}else{
						$.messager.alert('提示',"单据作废失败,请联系开发人员！"); 
					}
				}
			}else if(data.info=="1"){  // 审核或者审批
				if(data.msg=="success"){
					// 审核或者审批成功
					if(data.msgInfo !=null && data.msgInfo !="" &&data.msgInfo !='success'){
						$.messager.alert("提示",data.msgInfo,'info');
					}else{
						if($(obj).attr("id").indexOf("APPROVE_BUT")>0){    // 审批
							// 更新该单据最后一级的审批结果（审批通过）
							var approveInput=$(obj).next("input[id=approveObj]");
							var approveObj={};
							approveObj["approveLevel"]=$(approveInput).attr("level");   // 审批的等级
							approveObj["djId"]=$(approveInput).attr("djId");  // 审批的单据的id
							approveObj["isExamine"]=$(approveInput).attr("isExamine");   //审批的结果
							approveObj["examineContent"]=$(approveInput).attr("content");   //审批的内容
							approveObj["dsId"]=$(approveInput).attr("dsId");   // 审批的dsId
							$.ajax({
								url:_m_url+'approve/approveMaxLevel',
								type:'post',
								contentType:"application/json;charset=utf-8",
								dataType:"json",
								data:JSON.stringify(approveObj),
								async:false,
								success:function(data){
								},
								error : function() {
									// 请求失败后要执行的代码
									$.messager.alert('提示',"审批是发生异常，请联系开发");
								}
							});
						}
					}
					if(flag == '2'){
						cbhsAppLoadDataM(dsId,prefix,pkStr);
					}
				}else if(data.msg=='error'){
					// 判断单据是审核还是审批失败
					if($(obj).attr("id").indexOf("APPROVE_BUT")>0){    // 审批
						if(data.info !=null && data.info !=""){
							$.messager.alert('提示',data.msgInfo,'info');
						}else{
							$.messager.alert('提示',"<strong>单据审批失败</strong>,请联系开发人员！");
						}
					}else if($(obj).attr("id").indexOf("VERIFY_BUT")>0){   // 审核
						if(data.info !=null && data.info !=""){
							$.messager.alert('提示',data.msgInfo,'info');
						}else{
							$.messager.alert('提示',"<strong>单据审核失败<strong>失败,请联系开发人员！");
						}
					}
				}
			}
		}
	})
}
//明细界面的添加按钮 添加一行数据（有加载默认值）
function cbhsRowAdd(obj,flag){
	var gridName = "";
	var dsId = '';
	var tabType = '';
	if(flag == '5'){
		gridName = "fiveChengBen";
		dsId = 'ds_yz_cbhs_item5';
		tabType = 'cbhsTab.005';
	}else if(flag == '6'){
		gridName = "sixChengBen";
		dsId = 'ds_yz_cbhs_item6';
		tabType = 'cbhsTab.006';
	} 
	var allrow = $('#'+gridName).datagrid('getRows');
	for(var i=0;i<allrow.length;i++){
		$('#'+gridName).datagrid('endEdit',i);
	}
	// 获取datagrid
	// 明细加载默认值
	$.ajax({
		url:_m_url+'framework/defaultData',
		data:{'dsId':dsId,'addQrFlag':'1'},
		type:'post',
		async:false,
		success:function(data){
			var row={};
			var colns=$('#'+gridName).datagrid("options").columns[0];
			for(var i=0;i<colns.length;i++){
				var name=colns[i]["field"];
				row[name]="";
			}
			if(data[0]!=null){
				for(p in data[0]){
					row[p]=data[0][p];
				}
			}
			row.TAB_TYPE=tabType;
			$('#'+gridName).datagrid('appendRow',row);
			var lastIndex;
			$('#'+gridName).datagrid({
				onClickRow:function(rowIndex,rowData){
					$('#'+gridName).datagrid('endEdit', lastIndex);
					$('#'+gridName).datagrid('beginEdit', rowIndex);
					lastIndex = rowIndex;
				}
			});
			var changes=$('#'+gridName).datagrid('getChanges');
			for(var i=0;i<changes.length;i++){
				$('#'+gridName).datagrid('endEdit',i);
			} 
		}
	});
}